import { createRouter, createWebHashHistory } from 'vue-router';
import Layout from '@/layouts/index.vue';
import i18n from '@/locales';
const { global } = i18n;
export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录',
    },
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/errorPage/401.vue'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/errorPage/404.vue'),
    hidden: true,
  },
  {
    path: '/lock',
    name: 'lock',
    component: () => import('@/views/login/lock.vue'),
    meta: {
      title: '锁屏',
    },
    hidden: true,
    meta: { clearCache: true },
  },
];
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: 'Root',
    children: [
      {
        path: '/index',
        name: 'Index',
        component: () => import('../views/index/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: '/comp',
    component: Layout,
    name: 'Comp',
    meta: { title: global.t('route.comp'), icon: 'icon-medicine-chest' },
    children: [
      {
        path: '/pay',
        name: 'Pay',
        component: () => import('@/views/comp/pay.vue'),
        meta: {
          title: global.t('route.pay'),
          icon: 'icon-history',
        },
      },
      {
        path: '/reservation',
        name: 'Reservation',
        component: () => import('@/views/comp/reservation.vue'),
        meta: {
          title: global.t('route.reservation'),
          icon: 'icon-stopwatch',
        },
      },
      {
        path: '/history',
        name: 'History',
        component: () => import('@/views/comp/history.vue'),
        meta: {
          title: global.t('route.history'),
          icon: 'icon-chart-line',
        },
      },
      {
        path: '/visitor',
        name: 'Visitor',
        component: () => import('@/views/comp/visitor.vue'),
        meta: {
          icon: 'icon-chart-line',
          title: global.t('route.visitor'),
        },
      },
    ],
  },
  {
    path: '/hospital',
    component: Layout,
    name: 'Hospital',
    meta: { title: global.t('route.hospital'), icon: 'icon-hospital' },
    children: [
      {
        path: '/hospitalpay',
        name: 'Hospitalpay',
        component: () => import('@/views/hospital/hospitalpay.vue'),
        meta: {
          title: global.t('route.hospitalpay'),
          icon: 'icon-history',
        },
      },
      {
        path: '/room',
        name: 'Room',
        component: () => import('@/views/hospital/room.vue'),
        meta: {
          title: global.t('route.room'),
          icon: 'icon-hospital-bed',
        },
      },
    ],
  },
  {
    path: '/userinfor',
    component: Layout,
    name: 'Userinfor',
    meta: { title: global.t('route.userinfor'), icon: 'icon-user' },
    children: [
      {
        path: '/user',
        name: 'User',
        component: () => import('@/views/userinfor/user.vue'),
        meta: {
          title: global.t('route.user'),
          icon: 'icon-user',
        },
      },
      {
        path: '/visit',
        name: 'Visit',
        component: () => import('@/views/userinfor/visit.vue'),
        meta: {
          title: global.t('route.Visit'),
          icon: 'icon-bank-card',
        },
      },
      {
        path: '/role',
        name: 'Role',
        component: () => import('@/views/userinfor/role.vue'),
        meta: {
          title: global.t('route.role'),
          icon: 'icon-right-user',
        },
      },
      {
        path: '/admin',
        name: 'Admin',
        component: () => import('@/views/userinfor/admin.vue'),
        meta: {
          title: global.t('route.admin'),
          icon: 'icon-people-upload',
        },
      },
    ],
  },
  {
    path: '/department',
    component: Layout,
    redirect: '/departments',
    name: 'Department',
    children: [
      {
        path: '/departments',
        name: 'Departments',
        component: () => import('../views/departments/index.vue'),
        meta: {
          title: global.t('route.departments'),
          icon: 'icon-renal',
        },
      },
    ],
  },
  {
    path: '/hospitals',
    component: Layout,
    name: 'Hospitals',
    meta: { title: global.t('route.hospitals'), icon: 'icon-hospital-four' },
    children: [
      {
        path: '/hospitalList',
        name: 'HospitalList',
        component: () => import('@/views/hospitals/hospitalList.vue'),
        meta: {
          title: global.t('route.hospitalList'),
          icon: 'icon-hospital-four',
        },
      },
      {
        path: '/trends',
        name: 'Trends',
        component: () => import('@/views/hospitals/trends.vue'),
        meta: {
          title: global.t('route.trends'),
          icon: 'icon-positive-dynamics',
        },
      },
      {
        path: '/doctor',
        name: 'Doctor',
        component: () => import('@/views/hospitals/doctor.vue'),
        meta: {
          title: global.t('route.doctor'),
          icon: 'icon-nurse-cap',
        },
      },
      {
        path: '/scheduling',
        name: 'Scheduling',
        component: () => import('@/views/hospitals/scheduling.vue'),
        meta: {
          title: global.t('route.scheduling'),
          icon: 'icon-setting-config',
        },
      },
      {
        path: '/label',
        name: 'Label',
        component: () => import('@/views/hospitals/label.vue'),
        meta: {
          title: global.t('route.label'),
          icon: 'icon-tag-one',
        },
      },
      {
        path: '/drug',
        name: 'Drug',
        component: () => import('@/views/hospitals/drug.vue'),
        meta: {
          title: global.t('route.drug'),
          icon: 'icon-pills',
        },
      },
      {
        path: '/physical',
        name: 'Physical',
        component: () => import('@/views/hospitals/physical.vue'),
        meta: {
          title: global.t('route.physical'),
          icon: 'icon-inspection',
        },
      },
    ],
  },
  {
    path: '/errorPage',
    name: 'ErrorPage',
    component: Layout,
    meta: {
      title: global.t('route.errorPages'),
      icon: 'icon-link-cloud-faild',
    },
    children: [
      {
        path: '/404Page',
        name: '404Page',
        component: () => import('@/views/errorPage/404.vue'),
        meta: {
          title: global.t('route.page404'),
          icon: 'icon-link-cloud-faild',
        },
      },
      {
        path: '/401Page',
        name: '401Page',
        component: () => import('@/views/errorPage/401.vue'),
        meta: {
          title: global.t('route.page401'),
          icon: 'icon-link-interrupt',
        },
      },
    ],
  },
  // {
  //   path: '/lock',
  //   name: 'Lock',
  //   component: Layout,
  //   children: [
  //     {
  //       path: '/locks',
  //       name: 'Locks',
  //       component: () => import('@/views/lock/locks.vue'),
  //       meta: {
  //         title: global.t('route.page404'),
  //         icon: 'icon-link-cloud-faild',
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/locks',
  //   component: Layout,
  //   redirect: '/lock',
  //   name: 'Locks',
  //   children: [
  //     {
  //       path: '/lock',
  //       name: 'Lock',
  //       component: () => import('../views/lock/locks.vue'),
  //       meta: {
  //         title: '锁屏',
  //         icon: 'icon-renal',
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/department',
  //   component: Layout,
  //   redirect: '/departments',
  //   name: 'Department',
  //   children: [
  //     {
  //       path: '/departments',
  //       name: 'Departments',
  //       component: () => import('../views/departments/index.vue'),
  //       meta: {
  //         title: global.t('route.departments'),
  //         icon: 'icon-renal',
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '*',
  //   redirect: '/404',
  //   hidden: true,
  // },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
});

// reset router
export function resetRouter() {
  router.getRoutes().forEach((route) => {
    const { name } = route;
    if (name) {
      router.hasRoute(name) && router.removeRoute(name);
    }
  });
}

export default router;
